package com.modelo.dao.tipo;

import java.io.Serializable;
import java.util.List;

import org.hibernate.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Repository;

import com.modelo.dao.comun.HibernateBaseDAO;
import com.modelo.entity.Tipo;

@Repository
public class TipoDAO extends HibernateBaseDAO<Tipo> implements ITipoDAO, Serializable {
	private static final Logger log = LoggerFactory.getLogger(TipoDAO.class);
	public static final String NOMBRE = "nombre";
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public static TipoDAO getFromApplicationContext(ApplicationContext ctx) {
		return (TipoDAO) ctx.getBean("TipoDAO");
	}

	@Autowired
	public TipoDAO(SessionFactory sessionFactory) {
		super(sessionFactory);
	}

	public List<Tipo> findByExample(Tipo instance) {
		log.debug("finding Tipo instance by example");
		try {
			List<Tipo> results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: " + results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List<Tipo> findByNombre(Object nombre) {
		return findByProperty(NOMBRE, nombre);
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Tipo instance with property: " + propertyName + ", value: " + value);
		try {
			String queryString = "from Tipo as model where model." + propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}
}